package com.tm.dk.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.StringUtils;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.tm.dk.mapper.RealtimeMapper;
import com.tm.dk.service.RealtimeService;
import com.tm.entity.dto.CompanyDto;
import com.tm.exception.utils.Result;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

@Service
public class RealtimeServiceImpl extends ServiceImpl<RealtimeMapper, CompanyDto> implements RealtimeService {
   @Resource
   private RealtimeMapper realtimeMapper;


   public Page<CompanyDto> query(CompanyDto companyDto) {
      QueryWrapper<CompanyDto> wrapper = new QueryWrapper<CompanyDto>();
      wrapper.like(StringUtils.isNotBlank(companyDto.getCompany()),"company",companyDto.getCompany());
      Page<CompanyDto> page = new Page<CompanyDto>(companyDto.getPage(),companyDto.getPageSize());
      /*Page<CompanyDto> list  = realtimeMapper.page1(page,companyDto);*/
      Page<CompanyDto> companyDtoPage = realtimeMapper.selectPage(page, wrapper);
      return companyDtoPage;
   }

   public Result add(CompanyDto companyDto) {
      int insert = realtimeMapper.insert(companyDto);
      if(insert < 1){
         return Result.error();
      }
      return Result.success();
   }

   public Result update1(CompanyDto companyDto) {
      QueryWrapper<CompanyDto> wrapper = new QueryWrapper<CompanyDto>();
      wrapper.eq("id",companyDto.getId());
      int update = realtimeMapper.update(companyDto, wrapper);
      if(update < 1){
         return Result.error();
      }
      return Result.success();
   }



}